<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>案例绘编类型管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/frontEnd/images/favicon.ico">
    <link rel="stylesheet" href="/layuicms/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/layuicms/css/public.css" media="all" />
    <link rel="stylesheet" href="/kindeditor/themes/default/default.css" />
    <link rel="stylesheet" href="/kindeditor/plugins/code/prettify.css" />
    <script charset="utf-8" src="/kindeditor/kindeditor-all.js"></script>
    <script charset="utf-8" src="/kindeditor/lang/zh-CN.js"></script>
    <script charset="utf-8" src="/layuicms/js/x-layui.js"></script>
    <script type="text/javascript" src="/layuicms/layui/layui.js"></script>
    <style type="text/css">
        .ke-container.ke-container-default{
            width: 100% !important;
        }
    </style>
</head>

<body>
<!-- 添加和修改的弹出层开始 -->
<div style="padding: 5px 20px 0 0" id="addOrUpdateDiv">
    <form action="" method="post" class="layui-form" id="dataFrm" lay-filter="dataFrm">
        <div class="layui-form-item">
                <label class="layui-form-label">警示类型</label>
                <div class="layui-input-block">
                    <select name="safetyId" id="safetyId" lay-verify="required"  class="search_safety">
                        <option value="">请选择警示类型</option>
                    </select>
                </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">案例标题</label>
            <div class="layui-input-block">
                <input type="hidden" name="id" id="id">
                <input type="text" name="caseTitle" id="caseTitle" lay-verify="required" lay-reqtext="案例标题是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">案例详情</label>
            <div class="layui-input-block">
                <!-- 加载编辑器的容器 -->
                <textarea name="caseInfo" id="caseInfo" cols="100" rows="8" style="width:800px; height:300px;visibility:hidden;"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">是否可用</label>
                <div class="layui-input-inline">
                    <input type="radio" name="available" value="1" title="可用" checked="">
                    <input type="radio" name="available" value="0" title="不可用" >
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">排序码</label>
                <div class="layui-input-block">
                    <input type="text" id="ordernum" name="ordernum" lay-verify="required|number" autocomplete="off" placeholder="请输入排序码[>0]" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center;">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="doSubmit" id="doSubmit" ><span class="layui-icon layui-icon-add-1"></span>提交</button>
                <button type="reset" class="layui-btn layui-btn-warm"><span class="layui-icon layui-icon-refresh-1"></span>重置</button>
            </div>
        </div>
    </form>
</div>
<!-- 添加和修改的弹出层结束 -->
</body>
<script type="text/javascript" src="/layuicms/layui/layui.js"></script>
<script type="text/javascript">
        layui.use(['jquery','form','table','layer',],function(){
            var $ = layui.jquery;
            var form=layui.form;
            var layer = layui.layer;
            var editor = KindEditor.create('textarea[name="caseInfo"]', {
                allowFileManager : true,
                allowImageUpload:true,//允许上传图片
                allowFileManager:true, //允许对上传图片进行管理
                uploadJson:"/uploadImg",
                afterUpload: function(){this.sync();}, //图片上传后，将上传内容同步到textarea中
                afterBlur: function(){this.sync();},   //失去焦点时，将上传内容同步到textarea中
                items : [
                    'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
                    'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
                    'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
                    'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
                    'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
                    'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image',
                    'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
                    'anchor', 'link', 'unlink', '|', 'about'
                ]
            });
            var id = $(window.parent.document).find("#editId").val();
            $.get("/caseManagement/loadCaseById/"+id,function (res) {
                var data = res.data.item;
                $("input[name=available][value='1']").attr("checked", data.available == 1 ? true : false);
                $("input[name=available][value='0']").attr("checked", data.available == 0 ? true : false);
                form.render(); //更新全部
                //加载查询条件供应商的下拉列表
                $("#id").val(data.id);
                $("#caseTitle").val(data.caseTitle);
                editor.html(data.caseInfo);
                $("#caseInfo").val(data.caseInfo);
                $("#ordernum").val(data.ordernum);
                $.get("/safetyAlertType/loadAllsafetyAlertTypeForSelect",function(res){
                    var redata=res.data;
                    var dom=$(".search_safety");
                    var html='<option value="">请选择核心类型</option>'
                    $.each(redata,function(index,item){
                        if(data.safetyId===item.id){
                            html+='<option value="'+item.id+'" selected>'+item.typename+'</option>'
                        }else{
                            html+='<option value="'+item.id+'">'+item.typename+'</option>'
                        }
                    });
                    dom.html(html);
                    form.render("select");
                });
            });
            //添加和修改的提交
            $("#doSubmit").click(function () {
                //同步富文本和textarea里面的内容
                var data = $("#dataFrm").serialize();
                $.post("/caseManagement/updateCaseManagement",data,function (res) {
                    if(res.code==20000){
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.location.reload();
                    }
                    layer.msg(res.message);
                    parent.layer.close(index);
                })
            });
        });
</script>
</html>